<?php

  if (isset($_POST['submit0'])) { // If password entered...
    $word = $_POST['password']; // Variable set as entered password
    setcookie('textadmin', $word, time() + 31536000); // Cookie is set
  } else { // If password form filled in previously...
    if (isset($_COOKIE['textadmin'])) { // Check for cookie
      $word = $_COOKIE['textadmin']; // Variable set as cookie
    }
  }

?>

<?php $thisPage = "favorites"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Add to Favorites</title>
<meta name="robots" content="noindex,nofollow" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
</head>
<body>

<div id="wrap">

<?php

// Start password routine
  include_once('password.php');
  if ($word != $le_password) {

?>

<!-- password form //-->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>
<b>Enter password:</b>
<br />
<input type="password" name="password" size="25" maxlength="25" />
<br />
<input type="submit" name="submit0" value="Submit" />
</p>
</form>
<!-- password form_eof //-->

<?php

    // Routine to display password entry error message.
    if (isset($_POST['submit0'])) {
      if ($_POST['password'] != $le_password) {
        echo '<p">Incorrect password!</p>';
      }
    }

  } else {
// End password routine

?>

<?php include_once('navigation.php'); ?>

<?php

$url = $_POST['url'];
$linktext = $_POST['favorite'];
$link = '<br /><a href="http://'.$url.'">'. $linktext . '</a>';


$fileName = '../textfiles/Favorites.txt';



if ( strLen($url) != 0 && strLen($linktext) != 0 )
{
        $fp2 = fopen($fileName,"a") or die("Couldn't open $filename");
        fwrite($fp2, $link);
        fclose($fp2);
        
        $success == true;
}
else
{
        $success == false;
}





?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table align="center">
  <tr>
    <td>
        Favorite Name:(no capitals or file suffix)
    </td>
    
    <td>
        <input type="text" name="favorite" id="favorite" size="40" value="" maxlength="60" />
    </td>
  </tr>
  <tr>
    <td>
        Favorite URL:
    </td>
    
    <td>
        <input type="text" name="url" id="url" size="40" value="" maxlength="60" />
    </td>
  </tr>
  <tr>
    <td rowspan="2">  
        <input type="submit" name="submit1" value="Add Favorite"> 
    </td>
  </tr>
</table>
</form>

<?php 

if ($success == true)
{
    echo "<br />Favorites updated Successfully<br />";
}



?>










<?php

  } // Required for password routine

?>

</div>

</body>
</html>
